<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0028)http://jdbi.org/archive.html -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>


<title>abacus-common</title>

<script type="text/javascript" src="./css/ga.js"></script>
<script type="text/javascript">
	if (top.location != self.location)
		top.location.replace(self.location);
</script>

<link href="./css/css" rel="stylesheet" type="text/css"></link>
<link href="./css/css(1)" rel="stylesheet" type="text/css"></link>
<link rel="stylesheet" href="./css/syntax.css" type="text/css"></link>
<link rel="stylesheet" href="./css/screen.css" type="text/css"></link>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-65247258-1', 'auto');
  ga('send', 'pageview');
</script>

</head>
<body>
	<div id="site">
		<h1>
			<a href="./index.html">abacus-common</a> <span id="navigation"> <a href="./docs.html">Docs</a> | <a href="./download.html">Download</a>
				| <a href="./api-docs/index.html">Javadoc</a> | <a href="./faq.html">FAQ</a> | <a href="./community.html">Community</a>
			</span>
		</h1>
	</div>

	<div id="content">

		<div id="page">

			<h1>Programming in Android</h1>
			<p>
				Below features are supported for Android.			
			</p>
			
			<li>Most daily used APIs:
					<a href="./Pair_view.html">Pair</a>,  
					<a href="./Triple_view.html">Triple</a>, 
					<a href="./Tuple_view.html">Tuple</a>, 
					<a href="./Multiset_view.html">Multiset</a>,
					<a href="./BiMap_view.html">BiMap</a>,  
					<a href="./Multimap_view.html">Multimap</a>,
					<a href="./ImmutableList_view.html">ImmutableList</a>,
					<a href="./ImmutableSet_view.html">ImmutableSet</a>,
					<a href="./ImmutableMap_view.html">ImmutableMap</a>, 
					<a href="./Splitter_view.html">Splitter</a>, 
					<a href="./Joiner_view.html">Joiner</a>, 
					<a href="./Builder_view.html">Builder</a>, 
					<a href="./Difference_view.html">Difference</a>, 
				    <a href="./IOUtil_view.html">IOUtil</a>,
					<a href="./N_view.html">N</a> ...
				</li>
			
			<br />
			<li>A <a href="./parser.html">JSON Parser</a>: Easy to learn, simple to use, two times faster than Gson and more powerful.</li>
			
			<br />
			<li><a href="./http-client.html">The simplest synchronous/asynchronous HTTP client</a>: <a href="./api-docs/com/landawn/abacus/http/HttpClient.html">HttpClient</a> and <a href="./api-docs/com/landawn/abacus/http/OKHttpClient.html">OKHttpClient</a></li>
			
			<br />
			<li><a href="./web-services.html">Agile Restful Web service development</a>: <a href="./api-docs/com/landawn/abacus/http/HttpProxy.html">HttpProxy</a>, which is similar with <a href="http://square.github.io/retrofit/">Retrofit</a> and even simpler.</li>
			
			<br />
			<li><a href="./sqlite-executor.html">Most convenient utility for SQLite</a>: <a href="./api-docs/com/landawn/abacus/android/util/SQLiteExecutor.html">SQLiteExecutor</a> and <a href="./api-docs/com/landawn/abacus/util/SQLBuilder.html">SQLBuilder</a>. No configuration/Annotation</li>
		
			<br />
			<li><a href="./Stream_view.html">Stream</a> + <a href="./AsyncExecutor_Android_view.html">AsyncExecutor</a> + <a href="./ContinuableFuture_Android_view.html">ContinuableFuture</a> with Lambdas supported by <a href="https://github.com/evant/gradle-retrolambda">Retrolambda</a> -> <a href="https://github.com/ReactiveX/RxJava">RxJava</a></li>
			
			<br />
			<li><a href="./EventBus_view.html">EventBus</a> and <a href="./Util_Android_view.html">Util</a>. More at: <a href="http://www.landawn.com/api-docs/com/landawn/abacus/android/package-summary.html">Java API docs</a></li>
			
			<br />
			<p>The coming version Android studio is going to support <a href="http://developer.android.com/preview/j8-jack.html">Java 8 features</a>. 
			The Stream API provided in abacus-common mostly is consistent with the Stream API in JDK 8. It's very easy to replace with each other. 
			The implementation of Stream API in abacus-common is pretty straight forward. In a lot of scenarios, <a href="./functional-programming-in-java.html">it's even faster than the implementation in JDK 8</a>. 
			Besides int, long, double, other primitive types: boolean, char, byte, short, float are also supported by the Stream API in abacus-common. Additionally, a lot of methods(e.g. forEach, filter...) in <a href="./api-docs/com/landawn/abacus/util/N.html">N</a> are also designed to support functional programming...Enjoying
			<br />
			<i>
			Note: I tested on Android Studio 2.1 RC. and found couple of issues: 1), Instant run is not supported. 2), slow, 3), unable to show the variable value in debug. So maybe it's better to stay with Retrolambda before new Java 8 features become stable. 
			</i>
			</p>
			
			<li>Switch smoothly between UI and background threads by the fluent execute/callback APIs in <a href="./api-docs/com/landawn/abacus/android/util/AsyncExecutor.html">AsyncExecutor</a></li>
<!-- HTML generated using hilite.me --><div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">AsyncExecutor<span style="color: #333333">.</span><span style="color: #0000CC">executeWithThreadPool</span><span style="color: #333333">(()</span> <span style="color: #333333">-&gt;</span> <span style="color: #333333">{</span>
    <span style="color: #008800; font-weight: bold">return</span> accountService<span style="color: #333333">.</span><span style="color: #0000CC">createAccount</span><span style="color: #333333">(</span>signUpRequest<span style="color: #333333">);</span>
<span style="color: #333333">}).</span><span style="color: #0000CC">thenRunWithUIExecutor</span><span style="color: #333333">((</span>signUpResp<span style="color: #333333">,</span> signUpError<span style="color: #333333">)</span> <span style="color: #333333">-&gt;</span> <span style="color: #333333">{</span>
    signInButton<span style="color: #333333">.</span><span style="color: #0000CC">setText</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">&quot;SIGN UP&quot;</span><span style="color: #333333">);</span>
    ProgressBarTask<span style="color: #333333">.</span><span style="color: #0000CC">finish</span><span style="color: #333333">();</span>

    <span style="color: #008800; font-weight: bold">if</span> <span style="color: #333333">(</span>Util<span style="color: #333333">.</span><span style="color: #0000CC">check</span><span style="color: #333333">(</span>signUpResp<span style="color: #333333">))</span> <span style="color: #333333">{</span>
        <span style="color: #008800; font-weight: bold">final</span> LoginRequest signInRequest <span style="color: #333333">=</span> <span style="color: #008800; font-weight: bold">new</span> LoginRequest<span style="color: #333333">().</span><span style="color: #0000CC">setAccessToken</span><span style="color: #333333">(</span>accessToken<span style="color: #333333">).</span><span style="color: #0000CC">setLoginId</span><span style="color: #333333">(</span>signUpRequest<span style="color: #333333">.</span><span style="color: #0000CC">getEmailAddress</span><span style="color: #333333">())</span>
            <span style="color: #333333">.</span><span style="color: #0000CC">setLoginPassword</span><span style="color: #333333">(</span>signUpRequest<span style="color: #333333">.</span><span style="color: #0000CC">getPassword</span><span style="color: #333333">());</span>

        AsyncExecutor<span style="color: #333333">.</span><span style="color: #0000CC">executeWithThreadPool</span><span style="color: #333333">(()</span> <span style="color: #333333">-&gt;</span> <span style="color: #333333">{</span>
            <span style="color: #008800; font-weight: bold">return</span> accountService<span style="color: #333333">.</span><span style="color: #0000CC">login</span><span style="color: #333333">(</span>signInRequest<span style="color: #333333">);</span>
        <span style="color: #333333">}).</span><span style="color: #0000CC">thenRun</span><span style="color: #333333">((</span>signInResp<span style="color: #333333">,</span> signInError<span style="color: #333333">)</span> <span style="color: #333333">-&gt;</span> <span style="color: #333333">{</span>
            <span style="color: #008800; font-weight: bold">if</span> <span style="color: #333333">(</span>Util<span style="color: #333333">.</span><span style="color: #0000CC">check</span><span style="color: #333333">(</span>signInResp<span style="color: #333333">))</span> <span style="color: #333333">{</span>
                <span style="color: #008800; font-weight: bold">final</span> Account account <span style="color: #333333">=</span> signInResp<span style="color: #333333">.</span><span style="color: #0000CC">getAccount</span><span style="color: #333333">();</span>
                Settings<span style="color: #333333">.</span><span style="color: #0000CC">setUserId</span><span style="color: #333333">(</span>account<span style="color: #333333">.</span><span style="color: #0000CC">getId</span><span style="color: #333333">());</span>
                Settings<span style="color: #333333">.</span><span style="color: #0000CC">setUserName</span><span style="color: #333333">(</span>account<span style="color: #333333">.</span><span style="color: #0000CC">getFullName</span><span style="color: #333333">());</span>
                Settings<span style="color: #333333">.</span><span style="color: #0000CC">setRWSUserAccessToken</span><span style="color: #333333">(</span>signInResp<span style="color: #333333">.</span><span style="color: #0000CC">getUserAccessToken</span><span style="color: #333333">());</span>

                <span style="color: #008800; font-weight: bold">final</span> Intent intent <span style="color: #333333">=</span> <span style="color: #008800; font-weight: bold">new</span> Intent<span style="color: #333333">();</span>
                intent<span style="color: #333333">.</span><span style="color: #0000CC">putExtra</span><span style="color: #333333">(</span>Util<span style="color: #333333">.</span><span style="color: #0000CC">USER_ACCESS_TOKEN</span><span style="color: #333333">,</span> signInResp<span style="color: #333333">.</span><span style="color: #0000CC">getUserAccessToken</span><span style="color: #333333">());</span>
                setResult<span style="color: #333333">(</span>RESULT_OK<span style="color: #333333">,</span> intent<span style="color: #333333">);</span>
            <span style="color: #333333">}</span> <span style="color: #008800; font-weight: bold">else</span> <span style="color: #333333">{</span>
                startActivity<span style="color: #333333">(</span><span style="color: #008800; font-weight: bold">new</span> Intent<span style="color: #333333">(</span><span style="color: #008800; font-weight: bold">this</span><span style="color: #333333">,</span> SignInActivity<span style="color: #333333">.</span><span style="color: #0000CC">class</span><span style="color: #333333">));</span>
            <span style="color: #333333">}</span>

            finish<span style="color: #333333">();</span>
        <span style="color: #333333">});</span>
    <span style="color: #333333">}</span> <span style="color: #008800; font-weight: bold">else</span> <span style="color: #333333">{</span>
        <span style="color: #008800; font-weight: bold">if</span> <span style="color: #333333">(</span>signUpResp <span style="color: #333333">!=</span> <span style="color: #008800; font-weight: bold">null</span><span style="color: #333333">)</span> <span style="color: #333333">{</span>
            <span style="color: #008800; font-weight: bold">if</span> <span style="color: #333333">(</span>signUpResp<span style="color: #333333">.</span><span style="color: #0000CC">getRespCode</span><span style="color: #333333">()</span> <span style="color: #333333">==</span> ResponseCode<span style="color: #333333">.</span><span style="color: #0000CC">LOGIN_ID_NOT_AVAILABLE</span><span style="color: #333333">)</span> <span style="color: #333333">{</span>
                Util<span style="color: #333333">.</span><span style="color: #0000CC">showToast</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">&quot;Email address: &quot;</span> <span style="color: #333333">+</span> email <span style="color: #333333">+</span> <span style="background-color: #fff0f0">&quot; has been used. Please try with another one or go to sign in page to login &quot;</span> <span style="color: #333333">+</span>
                    <span style="background-color: #fff0f0">&quot;directly&quot;</span><span style="color: #333333">);</span>
            <span style="color: #333333">}</span> <span style="color: #008800; font-weight: bold">else</span> <span style="color: #333333">{</span>
                Util<span style="color: #333333">.</span><span style="color: #0000CC">showToast</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">&quot;Unable to create account due to&quot;</span><span style="color: #333333">,</span> signUpResp<span style="color: #333333">);</span>
            <span style="color: #333333">}</span>
        <span style="color: #333333">}</span> <span style="color: #008800; font-weight: bold">else</span> <span style="color: #333333">{</span>
            Util<span style="color: #333333">.</span><span style="color: #0000CC">showToast</span><span style="color: #333333">(</span><span style="background-color: #fff0f0">&quot;Unable to create account due to network or system error.&quot;</span><span style="color: #333333">);</span>
        <span style="color: #333333">}</span>
    <span style="color: #333333">}</span>
<span style="color: #333333">});</span>
</pre></div>


			<br />
			
		</div>

	</div>
</body>

</html>